﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 类的数据成员
{
    public class car
    {
        public double OilMeter;             //油表数值，单位：升
        public double OilVolume;           //油箱容量，单位：升
        public double OilCosumption;       //油耗。每百公里消耗汽油数量，单位：升
        public double Mileage;            //里程数，单位：公里
        static public int count;     //静态数据成员
        public car()
        {
            count++;
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            car car1 = new car();
            car1.OilCosumption = 50;
            car car2 = new car();
            car2.OilCosumption = 100;
            Console.WriteLine("car1的油耗：{0}", car1.OilCosumption);
            Console.WriteLine("car2的油耗：{0}", car2.OilCosumption);
            Console.WriteLine("car类的实例个数：{0}", car.count);     //在car类的构造函数中使静态数据成员count自增，也就是没调用一次构造函数，count就会加一，默认其初始值为0，也可在定义静态数据成员时为其赋值

        }
    }
}
